package com.gvfish.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gvfish.dao.ConstantDao;
import com.gvfish.entity.Constant;
@Service
public class ConstantManager {
	private final static String  SITE_NAME="siteName";
	private final static String DONAME="doName";
	private final static String SITE_DESCRIPTION="siteDescription";

	
	@Autowired
	private ConstantDao constantDao;
	
	public Map<String,String> getConstantMap(){
		Map<String,String > result =new HashMap<String,String>();
		List<Constant> constantList =constantDao.findAll();
		if(constantList==null||constantList.size()==0){
			constantDao.save(new Constant(SITE_NAME,""));
			constantDao.save(new Constant(DONAME,""));
			constantDao.save(new Constant(SITE_DESCRIPTION,""));
			constantList =constantDao.findAll();
		}
		for(int i=0;i<constantList.size();i++){
			Constant constant =constantList.get(i);
			result.put(constant.getKey(), constant.getValue());
		}
		return result;
	}
	public List<Constant> findAll(){
		return constantDao.findAll();
	}
}
